package me.zk.practice1;

import cn.hutool.core.util.StrUtil;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @Author: zhang kai
 * @Date: 2023/04/06
 * @Description:
 */
public class CollectionsTest {
    public static void main(String[] args) throws Exception {
//        testSynchronizedList();

        System.out.println(StrUtil.center("",2,"%"));
    }

    public static void testEmptyList(){
        List emptyList = Collections.EMPTY_LIST;
        emptyList.add(1);
        System.out.println(emptyList);
    }

    public static void testSynchronizedList() throws InterruptedException {
        List<Integer> list = new ArrayList<Integer>();
        final List<Integer> list2 = Collections.synchronizedList(list);

        for (int i = 0; i< 100; i++) {
            new Thread(() -> add(list)).start();
        }
        TimeUnit.SECONDS.sleep(2);
        System.out.println(list.size());
    }

    public static void add(List list) {
        for (int i = 0; i< 100; i++) {
            list.add(1);
        }
    }
}
